<?php
/**
 * 相似分类列表，按 click 倒序读取前5个
 */
class SimilarCates extends CWidget
{
	public $pid;
	public $limit = 6;

	public function run(){
		$cates = $this->getCates();
		foreach($cates as $c){
			echo CHtml::link($c->name,array('item/list','cid'=>$c->cid),array('traget'=>'_blank','title'=>$c->name));
		}
	}

	protected function getCates(){
		$currentId = (int)$_GET['cid'];
		$criteria = new CDbCriteria();
		$criteria->condition = 'parent_cid=:pid and cid!=:curId';
		$criteria->order = 'click desc';
		$criteria->limit = $this->limit;
		$criteria->params = array(':pid'=>$this->pid,':curId'=>$currentId);
		$cates = Cates::model()->findAll($criteria);
		if(!count($cates))
			$cates[] = Cates::model()->find('cid=:pid',array(':pid'=>$this->pid));
		return $cates;
	}
}